package edu.unf.cen6940.web;

import edu.unf.cen6940.dao.ThesisDAO;
import edu.unf.cen6940.dao.ThesisstatusDAO;

import edu.unf.cen6940.domain.Thesis;
import edu.unf.cen6940.domain.Thesisstatus;

import edu.unf.cen6940.service.ThesisstatusService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;

/**
 * Spring MVC controller that handles CRUD requests for Thesisstatus entities
 * 
 */

@Controller("ThesisstatusController")
public class ThesisstatusController {

	/**
	 * DAO injected by Spring that manages Thesis entities
	 * 
	 */
	@Autowired
	private ThesisDAO thesisDAO;

	/**
	 * DAO injected by Spring that manages Thesisstatus entities
	 * 
	 */
	@Autowired
	private ThesisstatusDAO thesisstatusDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Thesisstatus entities
	 * 
	 */
	@Autowired
	private ThesisstatusService thesisstatusService;

	/**
	 * Delete an existing Thesisstatus entity
	 * 
	 */
	@RequestMapping("/deleteThesisstatus")
	public String deleteThesisstatus(@RequestParam Integer thesisStatusIdKey) {
		Thesisstatus thesisstatus = thesisstatusDAO.findThesisstatusByPrimaryKey(thesisStatusIdKey);
		thesisstatusService.deleteThesisstatus(thesisstatus);
		return "forward:/indexThesisstatus";
	}

	/**
	 * Delete an existing Thesis entity
	 * 
	 */
	@RequestMapping("/deleteThesisstatusThesises")
	public ModelAndView deleteThesisstatusThesises(@RequestParam Integer thesisstatus_thesisStatusId, @RequestParam Integer related_thesises_thesisId) {
		ModelAndView mav = new ModelAndView();

		Thesisstatus thesisstatus = thesisstatusService.deleteThesisstatusThesises(thesisstatus_thesisStatusId, related_thesises_thesisId);

		mav.addObject("thesisstatus_thesisStatusId", thesisstatus_thesisStatusId);
		mav.addObject("thesisstatus", thesisstatus);
		mav.setViewName("thesisstatus/viewThesisstatus.jsp");

		return mav;
	}

	/**
	 * Select the Thesisstatus entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteThesisstatus")
	public ModelAndView confirmDeleteThesisstatus(@RequestParam Integer thesisstatusIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesisstatus", thesisstatusDAO.findThesisstatusByPrimaryKey(thesisstatusIdKey));
		mav.setViewName("thesisstatus/deleteThesisstatus");

		return mav;
	}

	/**
	 */
	@RequestMapping("/thesisstatusController/binary.action")
	public ModelAndView streamBinary(@ModelAttribute HttpServletRequest request, @ModelAttribute HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("streamedBinaryContentView");
		return mav;

	}

	/**
	 * Save an existing Thesis entity
	 * 
	 */
	@RequestMapping("/saveThesisstatusThesises")
	public ModelAndView saveThesisstatusThesises(@RequestParam Integer thesisstatus_thesisStatusId, @ModelAttribute Thesis thesises) {
		Thesisstatus parent_thesisstatus = thesisstatusService.saveThesisstatusThesises(thesisstatus_thesisStatusId, thesises);

		ModelAndView mav = new ModelAndView();
		mav.addObject("thesisstatus_thesisStatusId", thesisstatus_thesisStatusId);
		mav.addObject("thesisstatus", parent_thesisstatus);
		mav.setViewName("thesisstatus/viewThesisstatus.jsp");

		return mav;
	}

	/**
	 * Create a new Thesis entity
	 * 
	 */
	@RequestMapping("/newThesisstatusThesises")
	public ModelAndView newThesisstatusThesises(@RequestParam Integer thesisstatus_thesisStatusId) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("thesisstatus_thesisStatusId", thesisstatus_thesisStatusId);
		mav.addObject("thesis", new Thesis());
		mav.addObject("newFlag", true);
		mav.setViewName("thesisstatus/thesises/editThesises.jsp");

		return mav;
	}

	/**
	 * Show all Thesis entities by Thesisstatus
	 * 
	 */
	@RequestMapping("/listThesisstatusThesises")
	public ModelAndView listThesisstatusThesises(@RequestParam Integer thesisStatusIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesisstatus", thesisstatusDAO.findThesisstatusByPrimaryKey(thesisStatusIdKey));
		mav.setViewName("thesisstatus/thesises/listThesises.jsp");

		return mav;
	}

	/**
	 * Register custom, context-specific property editors
	 * 
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	 * Save an existing Thesisstatus entity
	 * 
	 */
	@RequestMapping("/saveThesisstatus")
	public String saveThesisstatus(@ModelAttribute Thesisstatus thesisstatus) {
		thesisstatusService.saveThesisstatus(thesisstatus);
		return "forward:/indexThesisstatus";
	}

	/**
	 * View an existing Thesis entity
	 * 
	 */
	@RequestMapping("/selectThesisstatusThesises")
	public ModelAndView selectThesisstatusThesises(@RequestParam Integer thesisstatus_thesisStatusId, @RequestParam Integer thesises_thesisId) {
		Thesis thesis = thesisDAO.findThesisByPrimaryKey(thesises_thesisId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("thesisstatus_thesisStatusId", thesisstatus_thesisStatusId);
		mav.addObject("thesis", thesis);
		mav.setViewName("thesisstatus/thesises/viewThesises.jsp");

		return mav;
	}

	/**
	 * Select the child Thesis entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteThesisstatusThesises")
	public ModelAndView confirmDeleteThesisstatusThesises(@RequestParam Integer thesisstatus_thesisStatusId, @RequestParam Integer related_thesises_thesisId) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesis", thesisDAO.findThesisByPrimaryKey(related_thesises_thesisId));
		mav.addObject("thesisstatus_thesisStatusId", thesisstatus_thesisStatusId);
		mav.setViewName("thesisstatus/thesises/deleteThesises.jsp");

		return mav;
	}

	/**
	 * Edit an existing Thesisstatus entity
	 * 
	 */
	@RequestMapping("/editThesisstatus")
	public ModelAndView editThesisstatus(@RequestParam Integer thesisstatusIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesisstatus", thesisstatusDAO.findThesisstatusByPrimaryKey(thesisstatusIdKey));
		mav.setViewName("thesisstatus/editThesisstatus");

		return mav;
	}

	/**
	 * Edit an existing Thesis entity
	 * 
	 */
	@RequestMapping("/editThesisstatusThesises")
	public ModelAndView editThesisstatusThesises(@RequestParam Integer thesisstatus_thesisStatusId, @RequestParam Integer thesises_thesisId) {
		Thesis thesis = thesisDAO.findThesisByPrimaryKey(thesises_thesisId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("thesisstatus_thesisStatusId", thesisstatus_thesisStatusId);
		mav.addObject("thesis", thesis);
		mav.setViewName("thesisstatus/thesises/editThesises.jsp");

		return mav;
	}

	/**
	 * Select an existing Thesisstatus entity
	 * 
	 */
	//@RequestMapping("/viewThesisstatus")
	@RequestMapping("/selectThesisstatus")
	public String selectThesisstatus(@RequestParam Integer thesisstatusIdKey, Model model) {

		model.addAttribute("thesisstatus", thesisstatusDAO.findThesisstatusByPrimaryKey(thesisstatusIdKey));
		return "thesisstatus/viewThesisstatus";
	}

	/**
	 * Show all Thesisstatus entities
	 * 
	 */
	@RequestMapping("/indexThesisstatus")
	public String listThesisstatuss(Model model) {

		model.addAttribute("thesisstatuss", thesisstatusService.loadThesisstatuss());
		return "thesisstatus/listThesisstatuss";
	}

	/**
	 * Create a new Thesisstatus entity
	 * 
	 */
	@RequestMapping("/newThesisstatus")
	public ModelAndView newThesisstatus() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesisstatus", new Thesisstatus());
		mav.addObject("newFlag", true);
		mav.setViewName("thesisstatus/editThesisstatus");

		return mav;
	}

	/**
	 * Entry point to show all Thesisstatus entities
	 * 
	 */
	public String indexThesisstatus() {
		return "redirect:/indexThesisstatus";
	}
}